<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
    <script crossorigin="anonymous" integrity="sha384-vk5WoKIaW/vJyUAd9n/wmopsmNhiy+L2Z+SBxGYnUkunIxVxAv/UtMOhba/xskxh" src="https://lib.baomitu.com/jquery/3.4.1/jquery.min.js"></script>

    <script>
        $(function () {
            $("#reg_btn").on("click",function () {

                /*
                var url = "user/registSubmit.action"; //写好后台地址
                var data = $("#myform").serialize(); //将表单序列化
                $.post(url,data,function (obj) {
                    if(obj.state==1){
                        //alert("注册成功!");
                        location.href="pages/login.html";
                    }else{
                        alert("注册失败!");

                    }
                },"json");
                */
                var url = "user/registSubmitFile.action";
                var data = new FormData(document.getElementById("myform")) ;
                $.ajax({
                    url:url,
                    data:data,
                    dataType:"json",
                    method:"post",
                    async: true,
                    processData : false, // 使数据不做处理
                    contentType : false, // 不要设置Content-Type请求头
                    success:function (obj) {
                        if(obj.state==1){
                            alert("注册成功");
                            location.href="pages/login.html";
                        }
                    },
                    error:function (e) {
                        alert(e);
                    }
                });
            })
        })
    </script>
</head>
<body>
<form action="" method="post" id="myform">
    <p>用户名<input type="text" name="userName"></p>
    <p>密码<input type="text" name="userPassword"></p>
    <p>账号<input type="text" name="userAccount"></p>
    <p>备注<input type="text" name="remark"></p>
    <p>附件:<input type="file" name="userFile"></p>
    <p><input type="button" id="reg_btn" value="提交"> </p>
</form>
</body>
</html>